#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include "Stash.h"
Stash::Stash(size_t size){
  this->stashSize = size;
  this->stash = (char *)calloc(size,1); 
  info = new OperationInfo(0,0); 
}

OperationInfo *Stash::nonResidentStore(size_t size){
  this->info->setLatency(this->writeLatency * size);//
  this->info->setEnergy(this->writeEnergy * size);//
  return this->info;
}

OperationInfo *Stash::nonResidentLoad(size_t size){
  
  this->info->setLatency(this->readLatency * size);//
  this->info->setEnergy(this->readEnergy * size);//
  return this->info;

}

OperationInfo *Stash::store(void *val, unsigned long NVAddr, size_t size){

  assert(NVAddr + size < this->stashSize);
  /*value must be allocated and contain the data to move to the NV store*/
  memcpy(&(this->stash[NVAddr]), val, size);
  this->info->setLatency(this->writeLatency * size);//
  this->info->setEnergy(this->writeEnergy * size);//
  return this->info;

}

OperationInfo *Stash::load(void *buf, unsigned long NVAddr, size_t size){

  assert(NVAddr + size < this->stashSize);
  /*buf must be allocated and adequately sized for NVAddr*/
  memcpy(buf, &(this->stash[NVAddr]), size);
  this->info->setLatency(this->readLatency * size);//
  this->info->setEnergy(this->readEnergy * size);//
  return this->info;

}
